package com.qiyi.player.user.impls
{
   import com.qiyi.player.base.rpc.impl.BaseRemoteObject;
   import com.qiyi.player.base.logging.ILogger;
   import com.qiyi.player.base.pub.ProcessesTimeRecord;
   import flash.utils.getTimer;
   import flash.net.URLRequest;
   import flash.net.URLRequestMethod;
   import flash.net.URLVariables;
   import com.qiyi.player.base.utils.MD5;
   import flash.events.Event;
   import flash.utils.clearTimeout;
   import com.adobe.serialization.json.JSON;
   import com.qiyi.player.user.UserDef;
   import com.qiyi.player.base.rpc.RemoteObjectStatusEnum;
   import com.qiyi.player.base.logging.Log;
   import com.qiyi.player.base.utils.KeyUtils;
   
   public class UserCheckRemote extends BaseRemoteObject
   {
      
      public function UserCheckRemote(param1:String, param2:String) {
         this._userLevel = UserDef.USER_LEVEL_NORMAL;
         this._userType = UserDef.USER_TYPE_QIYI;
         this._log = Log.getLogger("com.qiyi.player.wonder.body.model.remote.UserCheckRemote");
         super(0,"UserCheckRemote");
         this._key = KeyUtils.getPassportKey(0);
         this._passportID = param1;
         this._P00001 = param2;
         _timeout = 2000;
         _retryMaxCount = 2;
      }
      
      private const MEMBER_CHECK_URL:String = "http://serv.vip.iqiyi.com/services/serveAuth.action";
      
      private const SERVER_ID:String = "b9494c7a0de576f1";
      
      private const PLATFORM:String = "b6c13e26323c537d";
      
      private const CHANNEL_ID:String = "afbe8fd3d73448c9";
      
      private var _passportID:String = "";
      
      private var _P00001:String = "";
      
      private var _userID:String = "";
      
      private var _userName:String = "";
      
      private var _userLevel:int;
      
      private var _userType:int;
      
      private var _key:String = "";
      
      private var _log:ILogger;
      
      public function get userID() : String {
         return this._userID;
      }
      
      public function get userName() : String {
         return this._userName;
      }
      
      public function get userLevel() : int {
         return this._userLevel;
      }
      
      public function get userType() : int {
         return this._userType;
      }
      
      override public function initialize() : void {
         ProcessesTimeRecord.STime_userInfo = getTimer();
         super.initialize();
      }
      
      override protected function getRequest() : URLRequest {
         var _loc1_:URLRequest = new URLRequest(this.MEMBER_CHECK_URL);
         _loc1_.method = URLRequestMethod.POST;
         var _loc2_:URLVariables = new URLVariables();
         _loc2_.sid = this.SERVER_ID;
         _loc2_.platform = this.PLATFORM;
         _loc2_.cid = this.CHANNEL_ID;
         _loc2_.v = MD5.calculate(this.PLATFORM + "_" + this.CHANNEL_ID + "_" + this.SERVER_ID + "_" + this._key);
         _loc2_.userId = this._passportID;
         if(this._P00001)
         {
            _loc2_.P00001 = this._P00001;
         }
         _loc1_.data = _loc2_;
         return _loc1_;
      }
      
      override protected function onComplete(param1:Event) : void {
         var digitalSignature:String = null;
         var tempDS:String = null;
         var event:Event = param1;
         clearTimeout(_waitingResponse);
         _waitingResponse = 0;
         ProcessesTimeRecord.usedTime_userInfo = getTimer() - ProcessesTimeRecord.STime_userInfo;
         try
         {
            _data = com.adobe.serialization.json.JSON.decode(_loader.data as String);
            if(_data.code == "A00000")
            {
               this._userID = _data.data.u;
               this._userName = _data.data.cu;
               this._userType = int(_data.data.v_type);
               digitalSignature = _data.data.v;
               tempDS = MD5.calculate(this.PLATFORM + "_" + this.CHANNEL_ID + "_" + this.SERVER_ID + "_" + this._userID + "_" + this._key);
               if(tempDS == digitalSignature)
               {
                  this._log.info("User check OK statusCode A00000");
                  this._userLevel = UserDef.USER_LEVEL_PRIMARY;
               }
               else
               {
                  this._log.info("digitalSignature Error for member privilege");
                  this._userLevel = UserDef.USER_LEVEL_NORMAL;
               }
            }
            else
            {
               this._log.info("Error for user check statusCode " + _data.code + ":" + _data.msg);
               this._userLevel = UserDef.USER_LEVEL_NORMAL;
            }
            super.onComplete(event);
         }
         catch(e:Error)
         {
            _userLevel = UserDef.USER_LEVEL_NORMAL;
            setStatus(RemoteObjectStatusEnum.DataError);
         }
      }
   }
}
